import type { PluginCreator, Root } from 'postcss';

interface Options { }

const tagSeletors = [
  'view',
  'scroll-view',
  'swiper',
  'swiper-item',
  'image',
  'text',
  'rich-text',
  'progress',
  'button',
  'checkbox',
  'form',
  'input',
  'label',
  'picker',
  'picker-view',
  'radio',
  'switch',
  'textarea',
  'navigator',
  'audio',
  'image',
  'video',
  'map'
];

export const postcssWX2ui: PluginCreator<Options> = (options = {}) => {
  return {
    postcssPlugin: 'postcss-wx2ui',
    process(root: Root, postcss) {
      root.walkRules((rule, index) => {
        if (rule.selector && tagSeletors.includes(rule.selector)) {
          rule.selector = '.ui-' + rule.selector;
        }
      });
    }
  }
}

postcssWX2ui.postcss = true


